package com.invest.utils.rest;


import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * <p>注释</p>
 *
 * @author yuyizhao
 * @version v0.1 2016/3/9 Exp
 */
@Configuration
public class RestTemplateFactory {

    // 超时时间
    private static final int TIME_OUT = 3000;

    private static RestTemplate restTemplate;
    static {
        restTemplate = build();
    }

    public static RestTemplate instance(){
        return restTemplate;
    }

    private static RestTemplate build(){
        RestTemplate template = new RestTemplate();
        SimpleClientHttpRequestFactory factory = (SimpleClientHttpRequestFactory)template.getRequestFactory();
        factory.setConnectTimeout(TIME_OUT);
        factory.setReadTimeout(TIME_OUT);
        return template;
    }


}
